--[[
Dialog:
能读取layout文件的对话框的基础定义，基类
--]]

-- class: Dialog
Dialog = DlgBase:DeriveClass();

function Dialog:DeriveClass(dlgTypeName, layoutName, sub)
    sub = sub or { };
    setmetatable(sub, Dialog);
    sub.__index = sub;
    sub._DlgType = dlgTypeName;
    sub._LayoutName = layoutName;
    --sub._funcID = funcID or 0;
    DlgMgr:RegisterDlg(sub, dlgTypeName);
    return sub;
end

-- return: 获取当前对话使用的layout文件
function Dialog:GetLayoutName()
    return self._LayoutName;
end

-- return: 获取当前对话使用的layout文件所在的功能ID 7UI/funcID/layout下
function Dialog:GetFuncID()
    return self._funcID;
end

-- 创建窗口的初始化
-- return: 一个Window句柄
function Dialog:PrepareInit()
    return LuaMidInterface.windowMgr:LoadWindow(self:GetLayoutName());
end

-- 窗口初始化完毕，OnInit调用之前的初始化处理
function Dialog:BeforeInit()
    local closeBtn = self:GetWindow():TryGetCloseButton();
    if closeBtn ~= nil then
        closeBtn:SetClickHandler(self, self.Close);
    end
end

-- 从父窗口派生子窗口
function Dialog.DeriveDlg(baseDlg, deriveDlgName, layoutName, funcID, sub)
    subDlg = DeriveClass(baseDlg, sub);
    subDlg._DlgType = deriveDlgName;
    subDlg._LayoutName = layoutName or baseDlg._LayoutName;
    subDlg._funcID = funcID or baseDlg._funcID;
    DlgMgr:RegisterDlg(subDlg, deriveDlgName);
    return subDlg;
end